<?php
class CategoryService{

	public  $dbutil;
	function __construct($dbutil){
		$this->dbutil =  $dbutil;
	}
	/**
	 *
	 * 获取Category的子节点
	 */
	public function getCategoryId($categoryId) {
		$sql = "SELECT category_id from post_category WHERE category_id = ".$categoryId." OR parent = ".$categoryId;
		$result = $this->dbutil->get_results ( $sql );
		$categoryIds = "";
		foreach ($result as $k => $val) {
			$categoryIds .= $val->category_id . ",";
		}
		return $categoryIds;
	}
    /**
     *
     * 得到文章分类的父亲分类
     */
    public function getPCategory($categoryId) {
        $sql = "SELECT * from post_category WHERE  category_id = ".$categoryId;
        $result = $this->dbutil->get_results ( $sql );
        $category =$result [0];
        if($category->parent == 1){
            return $category;
        }else{
            $sql = "SELECT * from post_category WHERE  category_id = ".$category->parent;
            $parent = $this->dbutil->get_results ( $sql );
            return $parent[0];
        }

    }
	
}